package com.mobileapp.baliairport.src.main;



import java.util.ArrayList;

import com.mobileapp.baliairport.src.entity.listShop.shop;
import com.mobileapp.baliairport.src.listFlight.flightList.MyAdapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class fragmentShop extends Fragment{
	
	
	public static ArrayList<shop> shopdb = new ArrayList<shop>();
	public static shop shop;
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		
		View view = inflater.inflate(R.layout.shop_activity, container, false);
		MainTabActivity.bar.setTitle("SHOP");
		MainTabActivity.bar.setDisplayHomeAsUpEnabled(false);
		MainTabActivity.titleback = "";
		
		if(this.shopdb.isEmpty()){
			
		}else{
			this.shopdb.clear();
		}
		this.addShop("Orange Shop", "Bukan Toko Biasa","Sangat Murah Banget", "http://blablabla.com");
		this.addShop("Blue Shop", "Bukan Toko Biasa","Sangat Murah Banget", "http://blablabla.com");
		this.addShop("Red Shop", "Bukan Toko Biasa","Sangat Murah Banget", "http://blablabla.com");
		
		
		ListView listview = (ListView) view.findViewById(R.id.listView2);
		listview.setAdapter(new MyAdapter(view.getContext()));
		return view;
	}
	
	public class MyAdapter extends BaseAdapter {
		private Context mContext;
		public MyAdapter(Context context) {
			// TODO Auto-generated constructor stub
			mContext = context;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return shopdb.size();
			//return 0;
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return shopdb.get(arg0);
			//return null;
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			View listView;
			if (convertView == null) {
				listView = new View(mContext);
				LayoutInflater inflater = getLayoutInflater(getArguments());
				listView = inflater.inflate(R.layout.list_item_shop, parent, false);
			} else {
				listView = (View) convertView;
			}

			/*
			 * ListAdapter adapter = new SimpleAdapter(this, menuItems,
			 * R.layout.list_item, new String[] { KEY_NAME, KEY_DESC, KEY_COST
			 * }, new int[] { R.id.name, R.id.desciption, R.id.cost });
			 * 
			 * setListAdapter(adapter);
			 */

			TextView txtShop = (TextView) listView.findViewById(R.id.textView1);
			TextView txtTagDesc = (TextView) listView.findViewById(R.id.textView2);
			
			// txtID.setText(menuItems.get(position).get(KEY_NAME));
			// txtID.setText(test[position]);
			txtShop.setText(shopdb.get(position).getShopname());
			txtTagDesc.setTag(shopdb.get(position).getTagdescription());

			return listView;

		}
		
		
		
		
	}

	
	public void addShop(String name,String tagdescription,String description, String imagesrc){
		this.shop = new shop();
		this.shop.setShopname(name);
		this.shop.setImagesrc(imagesrc);
		this.shop.setDescription(description);
		this.shop.setTagdescription(tagdescription);
		this.shopdb.add(this.shop);
		
	}
}
